package com.cjx.yuanshenstartforumbackend.utils;

import com.cjx.yuanshenstartforumbackend.domain.vo.UserVo;

/**
 * ThreadLocal 工具类
 * @author cjx
 */
public class UserHolder {
    private static final ThreadLocal<UserVo> tl = new ThreadLocal<>();

    /**
     * 将用户信息存入ThreadLocal中
     * @param user 脱敏的用户信息
     */
    public static void saveUser(UserVo user){
        tl.set(user);
    }

    /**
     * 从ThreadLocal中获取用户信息
     * @return
     */
    public static UserVo getUser(){
        return tl.get();
    }

    /**
     * 将ThreadLocal的用户信息删除
     */
    public static void removeUser(){
        tl.remove();
    }
}
